package composite.general;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author：LJ
 * @Description：树枝构件
 * @Date: 2017/12/1
 * @Modified By:
 */
public class Composite extends Component {
    //构件容器
    private List<Component> components = new ArrayList<Component>();

    //增加一个叶子构件或树枝构件
    public void add(Component component) {
        component.setParent(this);
        components.add(component);
    }

    //删除一个叶子构件或树枝构件
    public void remove(Component component) {
        components.remove(component);
    }

    //获得分支下的所有叶子构件和树枝构件
    public List<Component> getChildren() {
        return components;
    }

}
